<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<title>添加用户</title>
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/themes/icon.css">
<link rel="stylesheet"
	href="${pageContext.request.contextPath}/themes/bootstrap/easyui.css">
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/jquery.easyui.min.js"></script>
<script type="text/javascript"
	src="${pageContext.request.contextPath}/js/easyui-lang-zh_CN.js"></script>
</head>

<body>

	<table id="func"></table>
	<div id="function">
		<form id="addFunction" method="post"
			style="margin-left: 100px; margin-top: 100px;">
			<div>
				<label for="name">功能名称:</label> <input class="easyui-textbox"
					name="name" style="width: 200px, height:40px;">
			</div>
			<div>
				<label for="name">是否叶子:</label> <select id="cc"
					class="easyui-combobox" name="state" style="width: 160px;">
					<option value="open">是</option>
					<option value="closed">否</option>
				</select>
			</div>
			<div>
				<label>选择位置:</label> <input id="functions" name="function"
					>
			</div>
			<a id="btn" href="#">提交</a>
		</form>
	</div>
	<script type="text/javascript">
		$(function() {
			$('#function').window({
				width : 600,
				height : 400,
				modal : true
			});
			$('#function').window("close");
			$('#btn').linkbutton({
				iconCls : 'icon-ok'
			});
			
			$('#addFunction').form({
				url : 'addFunction',
				success : function(data) {

					if (data == 'true') {
						$('#function').window('close');
						$('#addFunction').form('clear');
						$('#func').datagrid('reload');
						parent.$('#userRole').tree('reload');
					} else {
						$.messager.alert("消息提示", "添加失败");
					}
				}
			});
			$('#btn').bind('click', function() {
				$('#addFunction').submit();

			});
			$('#func').datagrid({
				url : 'showFunctions',
				pagination : true,
				rownumbers : true,
				columns : [ [ {
					field : 'ck',
					checkbox : true,
					width : 100
				}, {
					field : 'fid',
					title : '功能id',
					hidden : true,
					width : 100
				}, {
					field : 'fname',
					title : '功能名',
					width : 100
				}, {
					field : 'fstate',
					title : '是否为叶子',
					width : 100
				}, ] ],
				toolbar : [ {
					iconCls : 'icon-add',
					text : '添加',
					handler : function() {
						$('#functions').combotree({
							width : 160,
							multiple : true,
							url : 'showFuncs',
							required : true,
							cascadeCheck : false,
							onBeforeExpand:function(node){
								if (node.children.length>0) {
									return true;
								}else {
									return false;
								}
							},
							onBeforeCheck:function(node,checked){
								$('#functions').combotree('clear');
							}
							
						});
						$('#function').window('open');
					}
				} ]

			});
		})
	</script>
</body>
</html>